// 数据信息，代替数据库，mock api 获取数据从这个方法获取
const userList = [
  {
    id: 1,
    name: "张三",
    age: 18,
    sex: "男",
    address: "北京市",
  },
  {
    id: 2,
    name: "李四",
    age: 19,
    sex: "女",
    address: "上海市",
  },
  {
    id: 3,
    name: "王五",
    age: 20,
    sex: "男",
    address: "深圳市",
  },
];

export default [
  {
    url: "/user/list",
    method: "get",
    response: () => {
      return {
        code: 200,
        data: userList,
      };
    },
  },
  {
    // getUserById
    url: "/user/getUserById",
    method: "post",
    response: (req) => {
      const { id } = req.body;
      const user = userList.find((item) => item.id === Number(id));
      return {
        code: 200,
        data: user,
      };
    },
  },
  {
    url: "/user/add",
    method: "post",
    response: (req) => {
      const { name, age, sex, address } = req.body;
      const id = userList.length + 1;
      userList.push({
        id,
        name,
        age,
        sex,
        address,
      });
      return {
        code: 200,
        data: {},
      };
    },
  },
];
